'use strict';

import React, { Component } from 'react';
import ServerConfig from '../../config/serverConfig';
import Applist_listitem from './applist_listitem';

import {
  StyleSheet,
  ListView,
  Text
} from 'react-native';

class applist extends Component {
	constructor(props) {
	  	super(props);
		var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
	  	this.state = {
	  		dataSource: ds.cloneWithRows(['row 1', 'row 2']),
	  	};
	  	this._getapplist();
	}

	//通过http请求获取可以升级的app列表
	_getapplist(){
		var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
		fetch(ServerConfig.getAllBinList)
    	.then(res=>res.json())
    	.then((json)=>{
    		this.setState({
    			dataSource:ds.cloneWithRows(json)
    		});
    		//this.state.dataSource=ds.cloneWithRows(json);
    		//console.log(json);
    	});
	}

	render() {
	    return (
		    <ListView
		    	style={styles.contain}
		      	dataSource={this.state.dataSource}
		      	renderRow={(rowData) => <Applist_listitem appname={rowData}></Applist_listitem>}
		    ></ListView>
	    );
	}
}

const styles = StyleSheet.create({
	contain:{
		flex:1
	}
});


export default applist;